// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CloudStorageAccountWrapper.cs" company="AzureContrib (Open source library http://azurecontrib.codeplex.com)">
//   Microsoft Public License (Ms-PL)
// </copyright>
// <summary>
//   Exception for errors when handling Windows Azure Cloud Drives.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System;
using Microsoft.WindowsAzure;

namespace AzureContrib.WindowsAzure.StorageClient
{
	internal class CloudStorageAccountWrapper : ICloudStorageAccount
	{
		private readonly CloudStorageAccount cloudStorageAccount;

		internal CloudStorageAccountWrapper(CloudStorageAccount cloudStorageAccount)
		{
			this.cloudStorageAccount = cloudStorageAccount;
		}

		public Uri BlobEndpoint
		{
			get { return this.cloudStorageAccount.BlobEndpoint; }
		}

		public Uri QueueEndpoint
		{
			get { return this.cloudStorageAccount.QueueEndpoint; }
		}

		public Uri TableEndpoint
		{
			get { return this.cloudStorageAccount.TableEndpoint; }
		}

		public IStorageCredentials Credentials
		{
			get { return this.cloudStorageAccount.Credentials.Wrap(); }
		}

		public static implicit operator CloudStorageAccount(CloudStorageAccountWrapper cloudStorageAccountWrapper)
		{
			var wrappedCredentials =
				cloudStorageAccountWrapper.Credentials.Unwrap();

			return new CloudStorageAccount(
				wrappedCredentials,
				cloudStorageAccountWrapper.BlobEndpoint,
				cloudStorageAccountWrapper.QueueEndpoint,
				cloudStorageAccountWrapper.TableEndpoint);
		}

		public static CloudStorageAccountWrapper FromICloudStorageAccount(ICloudStorageAccount cloudStorageAccount)
		{
			return cloudStorageAccount as CloudStorageAccountWrapper;
		}

		public override string ToString()
		{
			return cloudStorageAccount.ToString();
		}

		public string ToString(bool exportSecrets)
		{
			return cloudStorageAccount.ToString();
		}
	}
}